Skip to content

Refactored project structure #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 20, 2020
Merged

Conversation

xstrengthofonex
Copy link
Contributor

Created basic project structure and moved production code into separate packages.

@unional
Copy link
Member

unional commented Jan 19, 2020

Should we aim for one public function per file or per some grouping criteria?

For example, the internal/filter/filter.go seems redundant. If the filter.go contains multiple filters, internal/filter.go seems to make more sense (of course, this is subject to the general go file structuring rules).

This is just a general rule or guideline and we can break them as needed. Just want to bring the question up front. This is related to O/C at the file level which affects mergability.

@xstrengthofonex
Copy link
Contributor Author

The main issue is that you should only have one package name per folder. If you put everything in the root internal folder, they would all be package internal, which would mess up all the namespaces.

@unional
Copy link
Member

unional commented Jan 19, 2020

The main issue is that you should only have one package name per folder. If you put everything in the root internal folder, they would all be package internal, which would mess up all the namespaces.

Sure, in that case, may be internal/filter/filterOnCoStyle.go (or filter-on-co-style.go depends on convention)?

@unional
Copy link
Member

unional commented Jan 19, 2020

Another comment is about CoStyle. Would it be too short? Would CollabStyle be a better name?

@xstrengthofonex
Copy link
Contributor Author

xstrengthofonex commented Jan 20, 2020

CollabStyle is a good name. I can also change the filename to filter/on_collab_style.go

@xstrengthofonex
Copy link
Contributor Author

xstrengthofonex commented Jan 20, 2020

How about changing the filter directory and package name to matcher? matcher is a more general name for the purpose of the package as opposed to filter which is more of an implementation strategy.

@unional
Copy link
Member

unional commented Jan 20, 2020

How about changing the filter directory and package name to matcher? matcher is a more general name for the purpose of the package as opposed to filter which is more of an implementation strategy.

I wouldn't worry too much about it because we are still at the very beginning, things are pretty much in flux.

In fact, these logic can be changed drastically and we may ended up with a query/graphQL like code that there is one function that handles all the detail filtering and perform some additional match based on the result.

So, until then, I would say what we currently have is ok.

My two cents. 🌷

@xstrengthofonex
Copy link
Contributor Author

xstrengthofonex commented Jan 20, 2020

I made the suggested changes. Don't worry about making suggestions, I'm using GoLand so refactoring is not a big problem.

unional
unional previously approved these changes Jan 20, 2020
Copy link
Collaborator

@akessner akessner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I fully understand what 1 package per folder means, but it's not a big deal and I'll take your word on it for now.

But we do need to update the test names.

"testing"
)

func TestFilterOnCoStyleReturnsEmpty(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We changed coStyle to colabStyle, but didn't update the test names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I forgot to update them. I'll do that.

@@ -0,0 +1,11 @@
package criteria

// CollabStyle ..
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more out of annoyance. The linter in VScode keeps complaining when you don't put a comment. I don't know how to turn off the linter rule. I'm ok to delete them. I mostly use goland, so it's not much of an issue for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There got to be a way. I would say it is ok to keep them in this PR,
and the next PR add .vscode/settings.json to turn it off and remove these comments.
And in the travis turn on any linter check. I know that go compiler do some linting itself, but don't know about which linter the vscode extension based on.

Copy link
Contributor Author

@xstrengthofonex xstrengthofonex Jan 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have looked, but wasn't able to find a way. I ended up just creating a snippet that added them automatically.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these comments supposed to be doc generating comments?

Copy link
Collaborator

@akessner akessner Jan 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see these are required. We should probably add godoc to the travis yaml.
https://golang.org/doc/effective_go.html#commentary

Since these comments are actually treated like code, they probably don't break the clean code "no comment" rules. And we should probably fill them in. Thoughts?
I'll raise this on the channel.


// OnCollabStyle ..
func OnCollabStyle(users []user.User, coStyle criteria.CollabStyle) (matchedUsers []user.User) {
matchedUsers = []user.User{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note for later.

If we use this style on all the match filters then we will end up looping through the entire user database multiple times.
We should make note to eventually only loop through the user DB once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this

Copy link
Contributor Author

@xstrengthofonex xstrengthofonex Jan 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also had a thought about this type of filter method. Because it's filtering out all the users that don't match with this specific criteria, if you were to use a chain of filters (in a functional way), the 'filtered out' users would not be present to be matched to other criterias. So, perhaps just returning the matching users might not be enough.

Instead we might want to consider using a new data structure that contains the user and a list of matches that have occurred. The function would be less of a filter and more of a matcher.

@akessner
Copy link
Collaborator

akessner commented Jan 20, 2020

Based on this: https://github.com/golang-standards/project-layout/blob/master/internal/README.md

Should we do internal/pckg/filter?
Btw, i prefer the package be named match, rather than filter.

@akessner akessner closed this Jan 20, 2020
@akessner
Copy link
Collaborator

Stupid phone, I did not mean to close the PR

@akessner akessner reopened this Jan 20, 2020
Copy link
Collaborator

@akessner akessner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the insights.

@akessner
Copy link
Collaborator

Umm, I just found this issue.
I'll refrain from making suggestions based on the go-standards library from now on.
There seems to be a lot of controversy around it.
golang-standards/project-layout#10

@xstrengthofonex xstrengthofonex merged commit 61df574 into master Jan 20, 2020
@xstrengthofonex xstrengthofonex deleted the refactor-project-structure branch January 20, 2020 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants